package com.eorchis.module.reminduserlink.ui.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eorchis.core.service.IBaseService;
import com.eorchis.core.springext.mvc.SessionConstant;
import com.eorchis.core.ui.commond.ResultState;
import com.eorchis.core.ui.controller.AbstractBaseController;
import com.eorchis.module.reminduserlink.domain.RemindUserBean;
import com.eorchis.module.reminduserlink.service.IRemindUserLinkService;
import com.eorchis.module.reminduserlink.ui.commond.RemindUserLinkQueryCommond;
import com.eorchis.module.reminduserlink.ui.commond.RemindUserLinkValidCommond;
import com.eorchis.module.user.domain.User;


/**
 * Title: RemindUserLinkController<br>
 * Description: 提醒用户关联表管理控制器<br>
 * Company: GoldGov<br>
 * Copyright @ 2012 GoldGov .All rights reserved.<br>
 * @author RongSL
 * @createDate 2016-05-06
 * @version $Revision$
 */
@Controller("remindUserLinkController")
@RequestMapping(value = RemindUserLinkController.MODULE_PATH)
public class RemindUserLinkController extends AbstractBaseController<RemindUserLinkValidCommond,RemindUserLinkQueryCommond> {
	// 模块页面根路径
	public static final String MODULE_PATH = "/module/reminduserlink";
	// 提醒用户关联表接口
	@Resource(name = "com.eorchis.module.reminduserlink.service.impl.RemindUserLinkServiceImpl")
	private IRemindUserLinkService remindUserLinkService;
	
	@Override
	public IBaseService getService() {
		return remindUserLinkService;
	}

	@Override
	public String getModulePath() {
		return MODULE_PATH;
	}
	
	/**
	 * 查询提醒列表
	 * @Date 2016-06-12
	 * @author RongSL
	 * @return List<RemindUserLink>
	 * @param RemindUserLinkQueryCommond
	 * */
	@RequestMapping("/remindUserList")
	public String remindUserList(RemindUserLinkQueryCommond commond,HttpServletRequest request,HttpServletResponse response,ResultState resultState){
		try {
			User user=(User) request.getSession().getAttribute(SessionConstant.USER_INFO);
			commond.setSearchReplyUserid(user.getUserId());
			List<RemindUserBean> list=(List<RemindUserBean>) remindUserLinkService.findRemindUserList(commond);
			commond.setResultList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}
	
	/**
	 * 删除提醒
	 * @Date 2016-06-13
	 * @author RongSL
	 * */
	@RequestMapping("/deleteRemindUserLink")
	public String deleteRemindUserLink(RemindUserLinkQueryCommond commond,HttpServletRequest request,HttpServletResponse response,ResultState resultState){
		ResultState rs=new ResultState();
		try {
			remindUserLinkService.deleteRemindUserLink(commond);
			rs.setMessage("删除成功！");
			rs.setState(ResultState.RESULT_STATE_SUCCESS);
		} catch (Exception e) {
			rs.setMessage("缺少ID！");
			rs.setState(ResultState.RESULT_STATE_FAIL);
		}finally{
			try {
				BeanUtils.copyProperties(rs, resultState);
			} catch (Exception e) {
			}
		}
		return "";
	}
	
	/**
	 * 查询未读提醒总数
	 * @Date 2016-06-24
	 * @author RongSL
	 * @return Integer
	 * @param RemindUserLinkQueryCommond
	 * */
	@RequestMapping("/RemindNewsUserNoReadCount")
	public void RemindUserNoReadCount(RemindUserLinkValidCommond commond,HttpServletRequest request){
		try{
			User user=(User) request.getSession().getAttribute(SessionConstant.USER_INFO);
			commond.setSearchReplyUserid(user.getUserId());
			String count[]=remindUserLinkService.findRemindUserNoReadCount(commond);
			commond.setRemindUserNoReadCount(count[0]);
			commond.setNewsUserNoReadCount(count[1]);
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("查询未读提醒总数出错！");
		}
	}
}
